package com.spsoft.vms.redis.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.spsoft.vms.redis.RedisService;
import com.spsoft.vms.redis.constant.RedisConstant;
import com.spsoft.vms.redis.service.BswjRedisService;
import io.micrometer.core.instrument.util.StringUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author wangy
 * @date 2024/2/23 13:16
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class BswjRedisServiceImpl implements BswjRedisService {

    private final RedisService redisService;

    public boolean getFpkjztSwitch(String deptCode) {
        String bswjInfo = getBswjInfo(deptCode);
        if (bswjInfo != null) {
            return JSONObject.parseObject(bswjInfo).getString("fpkjzt").equals("Y");
        }
        return false;
    }

    public boolean getBswjscztSwitch(String deptCode) {
        String bswjInfo = getBswjInfo(deptCode);
        if (bswjInfo != null) {
            return JSONObject.parseObject(bswjInfo).getString("bswjsczt").equals("Y");
        }
        return false;
    }

    @Override
    public String getSydwbh(String deptCode) {
        String bswjInfo = getBswjInfo(deptCode);
        if (bswjInfo != null) {
            return JSONObject.parseObject(bswjInfo).getString("sydwbh");
        }
        return null;
    }

    @Override
    public String getjkkpkpr(String deptCode) {
        String bswjInfo = getBswjInfo(deptCode);
        if (bswjInfo != null) {
            return JSONObject.parseObject(bswjInfo).getString("jkkpkpr");
        }
        return null;
    }

    private String getBswjInfo(String deptCode) {
        String result = redisService.getCacheObject(String.format(RedisConstant.REDIS_FULL_BSWJ_CACHE_KEY, deptCode));
        if (StringUtils.isEmpty(result)) {

            return null;
        }
        return result;
    }

}
